<template>
  <Panel title="涉疫车辆数" v-bind="$attrs">
    <div class="epidemic-header">
      <div class="sum-box">
        <div class="sum-item">
          <div class="sum">
            <div class="img to-day">
              <div class="number to-day-count">{{ state.todayTotal || 0 }}</div>
            </div>
            <div class="sum-desc">今日累计</div>
          </div>
        </div>
        <div class="sum-item">
          <div class="sum">
            <div class="img prev-day">
              <div class="number prev-day-count">{{ state.yesterdayTotal || 0 }}</div>
            </div>
            <div class="sum-desc">昨天总计</div>
          </div>
        </div>
      </div>
      <SequentialSame :data="{ ring: state.totalHb, same: state.totalTb }" class="epidemic-sequential-same">
      </SequentialSame>
    </div>

    <div class="flow-car">
      <carAnalysis :pieChartData="pieChartData" type="analysis" :guestCarList="guestCarList" :vanCarList="vanCarList">
      </carAnalysis>
    </div>

    <!-- 图表部分 -->
    <div class="line-chart">
      <ShadowLine :seriesData="seriesData" :title="title" :xDate="xDate" />
    </div>
  </Panel>
</template>
<script>
export default {
  name: 'EpidemicCar'
}
/**
 * @desc 涉疫车辆数
 * @author 邓清波
 * @date 2022/10/24
 * **/
</script>
<script setup>
import Panel from '../../components/panel'
import SequentialSame from '../../components/sequential-same/index.vue'
import { ref } from 'vue'
import ShadowLine from '../../components/charts/ShadowLine.vue'
import epidemicApi from '../../api/epidemic'
import carAnalysis from '../../components/car-analysis'
import useWatchStore from '@/hooks/useWatchStore'

const title = '近七日趋势'
const xDate = ref([])
const seriesData = ref([])
const state = ref({})

// 客车列表
const guestCarList = ref([])
// 货车列表
const vanCarList = ref([])
// 饼图数据
const pieChartData = ref([])
const colorList = ref([])

useWatchStore(getData)

/**
 * 获取疫情车辆来源数据
 * */
function getData(argParams) {
  const params = {
    roadType: argParams.roadType,
    province: '32',
    city: argParams.isProvince ? null : argParams.areaCode
  }
  epidemicApi.getPlagueVehicles(params).then(res => {
    console.log('疫情车辆来源', res)
    const data = res.data || {}

    state.value = data
    xDate.value = (res.data.sevenDayStatisticsModels || []).map(i => i.name)
    seriesData.value = [
      {
        gradientColor: [
          { offset: 0, color: 'rgb(183, 206, 250)' },
          { offset: 1, color: 'rgb(210, 229, 250)' }
        ],
        color: '#4287FE',
        data: (res.data.sevenDayStatisticsModels || []).map(i => Number(i.value))
      }
    ]
    guestCarList.value = data.khFlowStatisticModels.filter(i => i.name.indexOf('客') > -1)
    vanCarList.value = data.khFlowStatisticModels.filter(i => i.name.indexOf('货') > -1)
    pieChartData.value = [
      { name: '货车', value: data.hcTotal },
      { name: '客车', value: data.kcTotal },
      (colorList.value = ['#19bbce', '#266BF4'])
    ]
  })
}
</script>
<style lang="less" scoped>
.epidemic-header {
  height: 110px;
  display: flex;

  .sum-box {
    display: flex;
    flex: 1;

    .sum-item {
      height: 100%;
      margin-left: 16%;
    }

    .sum {
      width: 100px;
      text-align: center;
      justify-content: space-around;

      .img {
        width: 100%;
        height: 74px;
      }

      .to-day {
        width: 100%;
        background: url('../../assets/images/epidemic/epidemicCar-gl-vc.png') bottom no-repeat;
        background-size: 100%;
      }

      .to-day-count {
        font-size: 40px;
        height: 0.3rem;
        line-height: 40px;
        padding-top: 3px;
        color: #1793f0;
      }

      .prev-day {
        width: 100%;
        background: url('../../assets/images/epidemic/epidemicCar-gs-vc.png') bottom no-repeat;
        background-size: 100%;
      }

      .prev-day-count {
        font-size: 40px;
        height: 0.3rem;
        line-height: 40px;
        padding-top: 3px;
        color: #f66e06;
      }
    }

    .sum-desc {
      font-size: 12px;
      line-height: 30px;
      color: #555;
      text-align: center;
    }
  }

  .epidemic-sequential-same {
    height: 100%;
    padding-bottom: 12px;
    display: flex;
    width: 95px;
    flex-direction: column;
    justify-content: center;

    /deep/ & > div {
      margin: 5px 0;
    }
  }
}

.flow-car {
  display: flex;
  height: 170px;
}

.line-chart {
  flex: 1;
}
</style>
